//
//  RecomdItemView.m
//  JiaoX
//
//  Created by yinqy on 15/1/22.
//  Copyright (c) 2015年 北京娇羞科技有限公司. All rights reserved.
//

#import "RecomdItemView.h"

#define BTN_WIDTH 65
#define BTN_HEIGHT 37
#define NAME_FONT_SIZE 15
#define DESC_FONT_SIZE 12

@interface RecomdItemView()
{
    UIImageView *_imageView;
    UILabel *_nameLabel;
    UILabel *_descLabel;
    UIButton *_goBtn;
}
@end
@implementation RecomdItemView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setFrame:CGRectMake(0, 0, JXScreenW, RECOMD_ITEM_VIEW_HEIGHT)];
        
        _imageView = [[UIImageView alloc]initWithFrame:CGRectMake(JXPublicInset, JXPublicInset, RECOMD_ITEM_VIEW_HEIGHT-JXPublicInset*2, RECOMD_ITEM_VIEW_HEIGHT-JXPublicInset*2)];
        [_imageView.layer setCornerRadius:5];
        [self addSubview:_imageView];
        
        _goBtn = [[UIButton alloc]initWithFrame:CGRectMake(JXScreenW-JXPublicInset-BTN_WIDTH, (RECOMD_ITEM_VIEW_HEIGHT-BTN_HEIGHT)/2, BTN_WIDTH, BTN_HEIGHT)];
        [_goBtn setBackgroundImage:[UIImage resizedImage:@"btn_login_bg"] forState:UIControlStateNormal];
        [_goBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_goBtn setTitle:@"下载" forState:UIControlStateNormal];
        [_goBtn addTarget:self action:@selector(goBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_goBtn];
        
        _nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(_imageView.frame)+JXPublicInset, CGRectGetMinY(_imageView.frame)+JXPublicInset, CGRectGetMinX(_goBtn.frame)-JXPublicInset*2-CGRectGetMaxX(_imageView.frame), NAME_FONT_SIZE)];
        [_nameLabel setTextColor:[UIColor blackColor]];
        [_nameLabel setFont:[UIFont systemFontOfSize:NAME_FONT_SIZE]];
        [self addSubview:_nameLabel];
        
        _descLabel = [[UILabel alloc]initWithFrame:CGRectMake(_nameLabel.x, CGRectGetMaxY(_nameLabel.frame)+12, _nameLabel.width, DESC_FONT_SIZE)];
        [_descLabel setFont:[UIFont systemFontOfSize:DESC_FONT_SIZE]];
        [_descLabel setTextColor:JXColor(102, 102, 102)];
        [self addSubview:_descLabel];
    }
    return self;
}

-(void)setComdApp:(RecommendApp *)comdApp{
    _comdApp = comdApp;
    [_imageView sd_setImageWithURL:[NSURL URLWithString:comdApp.appIcon]];
    [_nameLabel setText:comdApp.appName];
    [_descLabel setText:comdApp.appDesc];
}


-(void)goBtnClick:(UIButton *)btn{
    //itms-apps://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=942925113
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:_comdApp.appUrl]];

}


@end
